import React, { Component, Fragment } from 'react';
import { connect } from 'dva'
import BaseTable from './baseTable'
import { Space, Popconfirm, Upload, Descriptions, Modal } from 'antd'
import constant from '../../constant/constant'

class VerificationTechnologyTable extends BaseTable {
    constructor(props) {
        super(props),
            this.state = {
                column: [
                    {
                        title: "技术编号", dataIndex: "id", key: "id",
                        render: (text, record, index) => {
                            return (
                                <p>{record.verificationTechnology.id}</p>
                            )
                        },
                        ...this.getColumnSearchProps("id")
                    },
                    { title: "技术名称", dataIndex: "technologyName", key: "technologyName",...this.getColumnSearchProps("technologyName") },
                    { title: "验证开始日期", dataIndex: "createdAt", key: "createdAt" },
                    
                    {
                        title: "验证协议", dataIndex: "verificationAgreement", key: "verificationAgreement",
                        render: (text, record, index) => {
                            if (record.verificationAgreement == null) {
                                return (
                                    <Upload
                                        action={constant.serverUrl + "/tvs/api/attachments/verificationfile/verificationAgreement"}
                                        data={{
                                            id: record.id,
                                            mechanismId: this.props.user.mechanismId
                                        }}
                                        onChange={this.onChangeUpload}
                                        name={"verificationAgreement"}
                                        onprogress={false}
                                        showUploadList={false}
                                    >
                                        <a>上传验证协议</a>
                                    </Upload>
                                )
                            } else {
                                return (
                                    <Space>
                                        <a>{record.verificationAgreement}</a>
                                        <Upload
                                            action={constant.serverUrl + "/tvs/api/attachments/verificationfile/verificationAgreement"}
                                            data={{
                                                id: record.id,
                                                mechanismId: this.props.user.mechanismId
                                            }}
                                            onChange={this.onChangeUpload}
                                            name={"verificationAgreement"}
                                            onprogress={false}
                                            onlist={false}
                                            showUploadList={false}
                                        >
                                            <a>修改</a>
                                        </Upload>
                                    </Space>
                                )
                            }
                        }
                    },
                    {
                        title: "验证数据", dataIndex: "dataauditReport", key: "dataauditReport",
                        render: (text, record, index) => {
                            if (record.verificationAgreement == null) {
                                return  "请先上传验证协议"
                            }
                            if (record.verificationAgreement != null) {
                                return (
                                    <Space>
                                        {record.dataauditReport == null ? <Upload
                                            action={constant.serverUrl + "/tvs/api/attachments/verificationfile/universalupload"}
                                            data={{
                                                id: record.id,
                                                mechanismId: this.props.user.mechanismId
                                            }}
                                            onChange={this.onChangeUpload}
                                            name={"dataauditReport"}
                                            onprogress={false}
                                            showUploadList={false}
                                        >
                                            <a>上传验证数据</a>
                                        </Upload> : 
                                        <Space>
                                        <a>{record.dataauditReport}</a>
                                        <Upload
                                            action={constant.serverUrl + "/tvs/api/attachments/verificationfile/universalupload"}
                                            data={{
                                                id: record.id,
                                                mechanismId: this.props.user.mechanismId
                                            }}
                                            onChange={this.onChangeUpload}
                                            name={"dataauditReport"}
                                            onprogress={false}
                                            showUploadList={false}
                                        >
                                            <a>修改</a>
                                        </Upload>
                                        </Space>}
                                    </Space>
                                )
                            }
                        }
                    },
                    {
                        title: "验证报告", dataIndex: "verificationReport", key: "verificationReport",
                        render: (text, record, index) => {
                            if (record.verificationAgreement == null) {
                                return (
                                    "请先上传验证协议"
                                )
                            } else {
                                return (
                                    <Space>
                                        {record.verificationReport == null ? <Upload
                                            action={constant.serverUrl + "/tvs/api/attachments/verificationfile/universalupload"}
                                            data={{
                                                id: record.id,
                                                mechanismId: this.props.user.mechanismId
                                            }}
                                            onChange={this.onChangeUpload}
                                            name={"verificationReport"}
                                            onprogress={false}
                                            showUploadList={false}
                                        >
                                            <a>上传验证报告</a>
                                        </Upload> : 
                                        <Space>
                                        <a>{record.verificationReport}</a>
                                        <Upload
                                            action={constant.serverUrl + "/tvs/api/attachments/verificationfile/universalupload"}
                                            data={{
                                                id: record.id,
                                                mechanismId: this.props.user.mechanismId
                                            }}
                                            onChange={this.onChangeUpload}
                                            name={"verificationReport"}
                                            onprogress={false}
                                            showUploadList={false}
                                        >
                                            <a>修改</a>
                                        </Upload>
                                        </Space>}
                                    </Space>
                                )
                            }
                        }
                    },
                    {
                        title: "验证声明", dataIndex: "verificationStatement", key: "verificationStatement",
                        render: (text, record, index) => {
                            if (record.verificationReport == null) {
                                return (
                                    "请先上传验证报告"
                                )
                            } else {
                                return (
                                    <Space>
                                    {record.verificationStatement == null ? <Upload
                                        action={constant.serverUrl + "/tvs/api/attachments/verificationfile/universalupload"}
                                        data={{
                                            id: record.id,
                                            mechanismId: this.props.user.mechanismId
                                        }}
                                        onChange={this.onChangeUpload}
                                        name={"verificationStatement"}
                                        onprogress={false}
                                        showUploadList={false}
                                    >
                                        <a>上传验证声明</a>
                                    </Upload> : 
                                    <Space>
                                    <a>{record.verificationStatement}</a>
                                    <Upload
                                        action={constant.serverUrl + "/tvs/api/attachments/verificationfile/universalupload"}
                                        data={{
                                            id: record.id,
                                            mechanismId: this.props.user.mechanismId
                                        }}
                                        onChange={this.onChangeUpload}
                                        name={"verificationStatement"}
                                        onprogress={false}
                                        showUploadList={false}
                                    >
                                        <a>修改</a>
                                    </Upload>
                                    </Space>}
                                </Space>
                                )
                            }
                        }
                    },
                    {
                        title: "验证声明许可协议", dataIndex: "licenseAgreement", key: "licenseAgreement",
                        render: (text, record, index) => {
                            if (record.verificationStatement == null) {
                                return (
                                    "请先上传验证声明"
                                )
                            } else {
                                return (
                                    <Space>
                                    {record.licenseAgreement == null ? <Upload
                                        action={constant.serverUrl + "/tvs/api/attachments/verificationfile/universalupload"}
                                        data={{
                                            id: record.id,
                                            mechanismId: this.props.user.mechanismId
                                        }}
                                        onChange={this.onChangeUpload}
                                        name={"licenseAgreement"}
                                        onprogress={false}
                                        showUploadList={false}
                                    >
                                        <a>上传验证声明许可协议</a>
                                    </Upload> : 
                                    <Space>
                                    <a>{record.licenseAgreement}</a>
                                    <Upload
                                        action={constant.serverUrl + "/tvs/api/attachments/verificationfile/universalupload"}
                                        data={{
                                            id: record.id,
                                            mechanismId: this.props.user.mechanismId
                                        }}
                                        onChange={this.onChangeUpload}
                                        name={"licenseAgreement"}
                                        onprogress={false}
                                        showUploadList={false}
                                    >
                                        <a>修改</a>
                                    </Upload>
                                    </Space>}
                                </Space>
                                )
                            }
                        }
                    },
                ]
            }
    }

    componentDidMount() {
        this.props.dispatch({
            type: "mechanismOperation/getVerificationTechnologyTableDataByMechanismId",
            data: {
                mechanismId: this.props.user.mechanismId
            }
        })
    }

    onChangeUpload = info => {
        if (info.file.status == "done") {
            if (info.file.response.code == 200) {
                this.props.dispatch({
                    type: "mechanismOperation/getVerificationTechnologyTableDataByMechanismId",
                    data: {
                        mechanismId: this.props.user.mechanismId
                    }
                })

                this.props.dispatch({
                    type: "app/setServerRes",
                    data: info.file.response
                })
            }
        }
    }

    uploadVerificationAgreement = id => {
        this.props.dispatch({
            type: "mechanismOperation/uploadVerificationAgreement"
        })
    }

    render() {
        return (
            <Fragment>
                {/* <Modal
                    title="技术详情"
                    width={1000}
                    visible={this.state.isTechnologyExaminationModalVisible}
                    onOk={this.handleTechnologyExaminationCancel}
                    onCancel={this.handleTechnologyExaminationCancel}>
                    <Descriptions>
                        <Descriptions.Item label="单位全称">{this.state.technologyInformation.companyName}</Descriptions.Item>
                        <Descriptions.Item label="单位性质">{this.state.technologyInformation.companyNature}</Descriptions.Item>
                        <Descriptions.Item label="地址">{this.state.technologyInformation.companyAddress}</Descriptions.Item>
                        <Descriptions.Item label="邮政编码">{this.state.technologyInformation.postalCode}</Descriptions.Item>
                        <Descriptions.Item label="法人代表">{this.state.technologyInformation.legalRepresentative}</Descriptions.Item>
                        <Descriptions.Item label="统一社会信用代码">{this.state.technologyInformation.socialCreditCode}</Descriptions.Item>
                        <Descriptions.Item label="联系人">{this.state.technologyInformation.contacts}</Descriptions.Item>
                        <Descriptions.Item label="联系方式">{this.state.technologyInformation.phone}</Descriptions.Item>
                        <Descriptions.Item label="身份证号码">{this.state.technologyInformation.idNumber}</Descriptions.Item>
                        <Descriptions.Item label="邮箱">{this.state.technologyInformation.email}</Descriptions.Item>
                        <Descriptions.Item label="技术名称">{this.state.technologyInformation.technologyName}</Descriptions.Item>
                        <Descriptions.Item label="技术目的">{this.state.technologyInformation.technologyTarget}</Descriptions.Item>
                        <Descriptions.Item label="技术原理">{this.state.technologyInformation.technologyPrinciple}</Descriptions.Item>
                        <Descriptions.Item label="技术的相关代替方案">{this.state.technologyInformation.technologyAlternatives}</Descriptions.Item>
                        <Descriptions.Item label="技术操作条件">{this.state.technologyInformation.operatingConditions}</Descriptions.Item>
                        <Descriptions.Item label="创新的描述">{this.state.technologyInformation.innovationDescription}</Descriptions.Item>
                        <Descriptions.Item label="相同或相似的技术验证">{this.state.technologyInformation.RepeatId ? this.state.technologyInformation.RepeatId : "无"}</Descriptions.Item>
                        <Descriptions.Item label="技术是否符合目标市场的法规要求">{this.state.technologyInformation.isStatue}</Descriptions.Item>
                        <Descriptions.Item label="目标市场设计的法律规章">{<a href={constant.serverUrl + constant.fileUrl.applicationUrl + this.state.technologyInformation.regulation}>{this.state.technologyInformation.regulation}</a>}</Descriptions.Item>
                        <Descriptions.Item label="目标市场设计的技术标准">{<a href={constant.serverUrl + constant.fileUrl.applicationUrl + this.state.technologyInformation.technicalStandard}>{this.state.technologyInformation.technicalStandard}</a>}</Descriptions.Item>
                        <Descriptions.Item label="适用于本技术的参考资料">{<a href={constant.serverUrl + constant.fileUrl.applicationUrl + this.state.technologyInformation.referenceMaterial}>{this.state.technologyInformation.referenceMaterial}</a>}</Descriptions.Item>
                    </Descriptions>
                </Modal> */}
                {super.render(this.state.column, this.props.dataSource,{pageSize:12})}
            </Fragment>
        )
    }
}

const mapStateToProps = state => {
    let dataSource = state.mechanismOperation.verificationTechnologyList
    let user = state.app.user
    return {
        dataSource,
        user
    }
}

export default connect(mapStateToProps)(VerificationTechnologyTable)